package pri.black.dogview.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import pri.black.dogview.domain.DeviceGpsLog;
import pri.black.dogview.domain.TableData;
import pri.black.dogview.domain.vo.CountDateLog;
import pri.black.dogview.mapper.DeviceGpsLogMapper;
import pri.black.dogview.service.IDeviceGpsLogService;

import java.util.List;

@Service
public class DeviceGpsLogServiceImpl extends ServiceImpl<DeviceGpsLogMapper, DeviceGpsLog> implements IDeviceGpsLogService {
    /**
     * 按时间统计每个小时的数量
     * @return
     */
    @Override
    public TableData dateCount(){
        List<CountDateLog> countDateLog = getBaseMapper().countDateLog();
        Integer[] datas = new Integer[countDateLog.size()];
        String[] xdatas = new String[countDateLog.size()];
        for (int i = 0; i < countDateLog.size(); i++) {
            datas[i] = countDateLog.get(i).getCount();
            xdatas[i] = countDateLog.get(i).getCountDate().split("-")[3];
        }
        TableData tableData = new TableData();
        tableData.setYdatas(datas);
        tableData.setXdatas(xdatas);
        return tableData;
    }

    @Override
    public List<DeviceGpsLog> query(String start, String end) {
        List<DeviceGpsLog> list = this.lambdaQuery()
                .gt(StringUtils.hasLength(start), DeviceGpsLog::getCreateTime, start)
                .lt(StringUtils.hasLength(end), DeviceGpsLog::getCreateTime, end)
                .list();
        return list;
    }
}
